package com.example.fw;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class UserHelper extends WebDriverHelperBase{

	public UserHelper(ApplicationManager manager) {
		super(manager);
	}

	public void delUsers(String i_username) {
		String xpathExpression= "/html/body/table[3]/tbody/tr[*]/td[1]/a";
		
		click(By.xpath("html/body/table[2]/tbody/tr/td[1]/a[8]"));
		click(By.xpath("html/body/div[2]/p/span[1]/a"));
		
		List<WebElement> rowdata = driver.findElements(By.xpath(xpathExpression));
		
		for (int indx = 3; indx <= rowdata.size(); indx++) {
			WebElement element = driver.findElement(By.xpath("/html/body/table[3]/tbody/tr["+indx+"]/td[1]/a"));
			String username = element.getText();
			
			if ( username == i_username ){
				// select a user
				click(By.xpath("/html/body/table[3]/tbody/tr["+indx+"]/td[1]/a"));
				// press a button "Delete User"
				click(By.xpath("html/body/div[4]/form[2]/input[3]"));
				// press a button "Delete Account"
				click(By.xpath("html/body/div[2]/form/input[4]"));
				return;
			}
		}
	}
}